home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 10.7 KB | 314 lines | [TEXT/ttxt] |
- in module DemoModule
-
- --*******************************************************************************
- --* Class name: Button
- --*
- --* Inherits from: Actuator
- --* Class type: Abstract, mixin
- --* Component: User Interface
- --*
- --* Description: This is a subclass of Actuator which provides the basic
- --* protocols for pushbutton functionality. It can be mixed
- --* in with any TwoDShape and gives it all the features of the
- --* PushButton core class.
- --*
- --* The main advantage of using this class is that it is very
- --* light weight (it uses just one presenter) and totally
- --* flexible in its appearance. You just have to supply the
- --* bitmaps for its pressed, released and disabled appearances.
- --* For even more customized appearances, you can override the
- --* setPressedAppearance, setReleasedAppearance,
- --* setDisabledAppearance, setActivatedAppearance methods.
- --* This class can also be combined with a Rollover class to
- --* give you a Rollover Button.
- --*
- --* Usage: Create a new multi-inherited class
- --* class myButton (TwoDShape, Button)
- --*
- --* IVs: pressedBitmap
- --* releasedBitmap
- --* disabledBitmap
- --* authordata
- --* pressAction
- --* releaseAction
- --* activateAction
- --* multiActivateAction
- --*
- --* Methods: handlePress
- --* handleRelease
- --* handleActivate
- --* handleMultiActivate
- --* setPressedAppearance
- --* setReleasedAppearance
- --* setDisabledAppearance
- --* setActivatedAppearance
- --* press
- --* release
- --* activate
- --* multiactivate
- --* enabledSetter
- --* init
- --* afterInit
- --*
- --* Required files: none
- --*
- --* Notes:
- --*
- --* Author: Su Quek - Kaleida Labs, Inc.
- --*******************************************************************************
- class Button (Actuator)
- inst vars
- pressedBitmap
- releasedBitmap
- disabledBitmap
- authordata
- pressAction
- releaseAction
- activateAction
- multiActivateAction
- end
-
- --*=============================================================================*
- --* Method name: handlePress
- --* Class: Button
- --* Usage: handlePress self
- --*-----------------------------------------------------------------------------*
- --* Description: Calls the function specified by pressAction.
- --*=============================================================================*
- method handlePress self {class Button} ->
- (
- if (self.pressAction != undefined) do
- self.pressAction self.authordata self
- )
-
- --*=============================================================================*
- --* Method name: handleRelease
- --* Class: Button
- --* Usage: handleRelease self
- --*-----------------------------------------------------------------------------*
- --* Description: Calls the function specified by releaseAction.
- --*=============================================================================*
- method handleRelease self {class Button} ->
- (
- if (self.releaseAction != undefined) do
- self.releaseAction self.authordata self
- )
-
- --*=============================================================================*
- --* Method name: handleActivate
- --* Class: Button
- --* Usage: handleActivate self
- --*-----------------------------------------------------------------------------*
- --* Description: Calls the function specified by activateAction.
- --*=============================================================================*
- method handleActivate self {class Button} ->
- (
- if (self.activateAction != undefined) do
- self.activateAction self.authordata self
- )
-
- --*=============================================================================*
- --* Method name: handleMultiActivate
- --* Class: Button
- --* Usage: handleMultiActivate self
- --*-----------------------------------------------------------------------------*
- --* Description: Calls the function specified by multiActivateAction.
- --*=============================================================================*
- method handleMultiActivate self {class Button} n ->
- (
- if (self.multiActivateAction != undefined) do
- self.multiActivateAction self.authordata self n
- )
-
- --*=============================================================================*
- --* Method name: setPressedAppearance
- --* Class: Button
- --* Usage: setPressedAppearance self
- --*-----------------------------------------------------------------------------*
- --* Description: Change the appearance of the shape to how it will appear
- --* when the mouse is pressed within the shape's boundary.
- --*=============================================================================*
- method setPressedAppearance self {class Button} ->
- (
- if (self.pressedBitmap != undefined) do
- self.boundary := self.pressedBitmap
- )
-
- --*=============================================================================*
- --* Method name: setReleasedAppearance
- --* Class: Button
- --* Usage: setReleasedAppearance self
- --*-----------------------------------------------------------------------------*
- --* Description: Change the appearance of the shape to how it will appear
- --* when the mouse is released or moves outside the shape's
- --* boundary.
- --*=============================================================================*
- method setReleasedAppearance self {class Button} ->
- (
- if (self.releasedBitmap != undefined) do
- self.boundary := self.releasedBitmap
- )
-
- --*=============================================================================*
- --* Method name: setDisabledAppearance
- --* Class: Button
- --* Usage: setDisabledAppearance self
- --*-----------------------------------------------------------------------------*
- --* Description: Change the appearance of the shape to how it will appear
- --* when the button is disabled.
- --*=============================================================================*
- method setDisabledAppearance self {class Button} ->
- (
- if (self.disabledBitmap != undefined) do
- self.boundary := self.disabledBitmap
- )
-
- --*=============================================================================*
- --* Method name: setActivatedAppearance
- --* Class: Button
- --* Usage: setActivatedAppearance self
- --*-----------------------------------------------------------------------------*
- --* Description: Change the appearance of the shape to how it will appear
- --* when the mouse is clicked within the shape's boundary.
- --*=============================================================================*
- method setActivatedAppearance self {class Button} ->
- (
- setReleasedAppearance self
- )
-
- --*=============================================================================*
- --* Method name: press
- --* Class: Button
- --* Usage: press self
- --*-----------------------------------------------------------------------------*
- --* Description: Displays and executes the appropriate bitmaps and actions
- --* when the mouse is pressed within the shape's boundary
- --*=============================================================================*
- method press self {class Button} ->
- (
- if not self.enabled do
- return
-
- nextmethod self
-
- setPressedAppearance self
-
- handlePress self
- )
-
- --*=============================================================================*
- --* Method name: release
- --* Class: Button
- --* Usage: release self
- --*-----------------------------------------------------------------------------*
- --* Description: Displays and executes the appropriate bitmaps and actions
- --* when the mouse is released or moves outside the shape's
- --* boundary.
- --*=============================================================================*
- method release self {class Button} ->
- (
- if not self.enabled do
- return
-
- nextmethod self
-
- setReleasedAppearance self
-
- handleRelease self
- )
-
- --*=============================================================================*
- --* Method name: activate
- --* Class: Button
- --* Usage: activate self
- --*-----------------------------------------------------------------------------*
- --* Description: Displays and executes the appropriate bitmaps and actions
- --* when the mouse is clicked within the shape's boundary.
- --*=============================================================================*
- method activate self {class Button} ->
- (
- if not self.enabled do
- return
-
- nextmethod self
-
- setActivatedAppearance self
-
- handleActivate self
- )
-
- --*=============================================================================*
- --* Method name: activate
- --* Class: Button
- --* Usage: activate self
- --*-----------------------------------------------------------------------------*
- --* Description: Displays and executes the appropriate bitmaps and actions
- --* when the mouse is clicked multiple times within the shape's
- --* boundary.
- --*=============================================================================*
- method multiActivate self {class Button} n ->
- (
- if not self.enabled do
- return
-
- nextmethod self n
-
- setActivatedAppearance self
-
- handleMultiActivate self n
- )
-
- --*=============================================================================*
- --* Method name: enabledSetter
- --* Class: Button
- --* Usage: enabledSetter self
- --*-----------------------------------------------------------------------------*
- --* Description: Displays the appropriate bitmaps when the button is enabled
- --* or disabled.
- --*=============================================================================*
- method enabledSetter self {class Button} value ->
- (
- nextmethod self value
-
- if value then
- setReleasedAppearance self
- else
- setDisabledAppearance self
-
- return value
- )
-
- --*=============================================================================*
- --* Method name: init
- --* Class: Button
- --* Usage: init self
- --*-----------------------------------------------------------------------------*
- --* Description: Initializes its IVs
- --*=============================================================================*
- method init self {class Button} #rest args
- #key pressedBitmap:(undefined) \
- releasedBitmap:(undefined) \
- disabledBitmap:(undefined) ->
- (
- apply nextmethod self args
- self.pressedBitmap := pressedBitmap
- self.releasedBitmap := releasedBitmap
- self.disabledBitmap := disabledBitmap
-
- self
- )
-
- --*=============================================================================*
- --* Method name: afterInit
- --* Class: Button
- --* Usage: afterInit self
- --*-----------------------------------------------------------------------------*
- --* Description: Sets up its appearance.
- --*=============================================================================*
- method afterInit self {class Button} #rest args ->
- (
- nextmethod self
- setReleasedAppearance self
- self
- )
-